package com.taokatao.cardmee.business.carddetail;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.taokatao.cardmee.R;
import com.taokatao.cardmee.Utils;
import com.taokatao.cardmee.WebActivity;
import com.taokatao.cardmee.api.model.CardDetailInfo;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CardDetailADLayout2 extends LinearLayout implements View.OnClickListener {
    @BindView(R.id.t_ad_title) TextView tAdTitle;
    @BindView(R.id.t_ad_desc) TextView tAdDesc;
    @BindView(R.id.i_ad_url) ImageView iAdUrl;

    @BindView(R.id.l_content) View lContent;

    private CardDetailInfo.AD mAD;

    public CardDetailADLayout2(Context context) {
        this(context, null);
    }

    public CardDetailADLayout2(Context context, AttributeSet attrs) {
        super(context, attrs);
        ButterKnife.bind(this, LayoutInflater.from(context).inflate(R.layout.layout_card_detail_ad_2, this));
    }

    public void setData(CardDetailInfo.AD ad) {
        if (ad == null) return;
        mAD = ad;
        tAdTitle.setText(mAD.adTitle);
        if (TextUtils.isEmpty(mAD.adUrl)) {
            iAdUrl.setVisibility(View.GONE);
            lContent.setOnClickListener(null);
        } else {
            iAdUrl.setVisibility(View.VISIBLE);
            lContent.setOnClickListener(this);
        }
    }

    @Override
    public void onClick(View v) {
        if (v == lContent) {
            if (mAD != null) {
                Utils.onMobEvent(getContext(), "clickLinkOfDetail");
                Intent intent = new Intent(getContext(), WebActivity.class);
                intent.putExtra("extra_url", mAD.adUrl);
                getContext().startActivity(intent);
            }
        }
    }
}
